//
//  ASCollectionContainer.swift
//  soapp
//
//  Created by zhu xietong on 2018/4/24.
//

import Foundation

import Eelay
import AsyncDisplayKit






open class ASCollectionContainer: ASColPaginatorController {
    
    open override var sections:TP.section{
        get{
            let sec:TP.section = [
                []
            ]
            return sec
        }
    }
    
    open override var selector:TP.selector{
        get{
            
            let sel = [
                "<\(page_load_section)>":cellType.self,
                ]
            return sel
        }
    }
    

    
    public var content:ASTermsContainer?
    {
        didSet{
            if let cnt = content
            {
                switch cnt {
                case .as_collection(title: let title, emptyMsg: let emptyMsg, net: let net, params: let params, node: let node, cellType: let cellType, detailType: let detailType, test: let test):
                    
                    self.title = title
                    self.cellType = cellType
                    self.detailType = detailType
                    if let emptyMessage = emptyMsg
                    {
                        self.paginator.empty_msg = emptyMessage
                    }
                    
                    if let p = params
                    {
                        paginator.parameters = p
                    }
                    
                    paginator.net = net
                    paginator.node = node
                    paginator.type = .full
                    paginator.in_test = test
                
                case .list(net: let net, node: let node, emptyMsg:let emptyMsg, params: let params, cellType: let cellType, detailType: let detailType, test: let test):
                    if let cellTp = cellType as? JoCellNode.Type
                    {
                        self.cellType = cellTp
                    }
                    self.detailType = detailType
                    if let emptyMessage = emptyMsg
                    {
                        self.paginator.empty_msg = emptyMessage
                    }
                    
                    if let p = params
                    {
                        paginator.parameters = p
                    }
                    
                    paginator.net = net
                    paginator.node = node
                    paginator.type = .full
                    paginator.in_test = test
                    
                    
                default:
                    break
                }
            }

        }
    }
    
    public var cellHeigth:CGFloat?
    
    public var detailType:UIViewController.Type?
    
    public var cellType:JoCellNode.Type = JoCellNode.self
    
    public var able = true
    
    public var didSelect:((NSMutableDictionary,ASCollectionContainer) ->Void)?
    
    public var back_color:UIColor = .table_bg_color
    
    public var viewDidLoadAction:((ASCollectionContainer)->Void)? = nil
    
    
    public required init()
    {
        super.init()
    }
    
    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override open func viewDidLoad() {
        
        super.viewDidLoad()
        
        let v = UIView()
        v.bsui.background(color: back_color)
        collectionView.backgroundView = v
        collectionView.backgroundColor = back_color
        
        //        load(sections: sections, selector: selector)
        //        if able
        //        {
        //            refresh()
        //        }
        self.viewDidLoadAction?(self)
    }
    
//    open override func collectionNode(_ collectionNode: ASCollectionNode, didSelectItemAt indexPath: IndexPath) {
// 
//        if let obj = collectionNode.cellData(at: indexPath)
//        {
//            if let detailT = self.detailType
//            {
//                let ctr = detailT.init()
//                if let atr = ctr as? MoAtrributeProtocol
//                {
//                    atr.mo.model = obj
//                }
//                
//                self.navigationController?.pushViewController(ctr, animated: true)
//            }
//            if let selectA = self.didSelect
//            {
//                selectA(obj,self)
//            }
//            
//        }
//    }
    
    
    
    
    
}
